package com.example.wishstar.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.wishstar.MyApplication;
import com.example.wishstar.db.UserDao;
import com.example.wishstar.db.UserDatabase;
import com.example.wishstar.model.Habit;
import com.example.wishstar.model.OldHabit;
import com.example.wishstar.model.OldWish;
import com.example.wishstar.repository.OldHabitWishRepository;

import java.util.List;

public class OldViewModel extends AndroidViewModel {
    private String TAG = "OldViewModel";
    private OldHabitWishRepository oldHabitWishRepository;
    private int userId;
    private LiveData<List<OldHabit>> oldHabitList;
    private LiveData<List<OldWish>> oldWishList;


    public OldViewModel(@NonNull Application application) {
        super(application);

        UserDatabase userDatabase = MyApplication.getUserDatabase();
        UserDao userDao = userDatabase.userDao();
        oldHabitWishRepository = new OldHabitWishRepository(userDao, MyApplication.getApi());
        userId = MyApplication.userId;
        oldHabitList = oldHabitWishRepository.getOldHabits(userId);
        oldWishList = oldHabitWishRepository.getOldWishs(userId);
    }

    public void refresh() {
        oldHabitWishRepository.refresh(userId);
    }

    public LiveData<List<OldHabit>> getOldHabit() {
        return oldHabitList;
    }

    public LiveData<List<OldWish>> getOldWish() {
        return oldWishList;
    }

    public void deleteHabitByHabitId(int habitId) {
        oldHabitWishRepository.deleteHabitByHabitId(habitId);
    }

    public void deleteWishByWishId(int wishId) {
        oldHabitWishRepository.deleteWishByWishId(wishId);
    }
}
